#ifndef _SPI_H
#define _SPI_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/spi_master.h"
#include "driver/gpio.h"

#define GPIO_LCD_DAT  13
#define GPIO_LCD_CLK  14
#define GPIO_LCD_CS   15
#define GPIO_LCD_DC   2
#define GPIO_LCD_RST  4

//LCD_CS
#define SPILCD_CS_SET gpio_set_level(GPIO_LCD_CS, 1)
#define SPILCD_CS_RESET  gpio_set_level(GPIO_LCD_CS, 0)

//LCD_RS/DC
#define SPILCD_RS_SET  gpio_set_level(GPIO_LCD_DC, 1)
#define SPILCD_RS_RESET  gpio_set_level(GPIO_LCD_DC, 0)

//LCD_RST
#define SPILCD_RST_SET  gpio_set_level(GPIO_LCD_RST, 1)
#define SPILCD_RST_RESET gpio_set_level(GPIO_LCD_RST, 0)

typedef struct
{ 					    
	uint16_t width;			//LCD ����
	uint16_t height;		//LCD �߶�
	uint16_t id;			//LCD ID
	uint8_t	wramcmd;		//��ʼдgramָ��
	uint8_t  setxcmd;		//����x����ָ��
	uint8_t  setycmd;		//����y����ָ��	 
}_lcd_dev;

//LCD����
extern _lcd_dev lcddev;

extern uint16_t  POINT_COLOR;  
extern uint16_t  BACK_COLOR;


//////////////////////////////////////////////////////////////////////////////////	 
//-----------------LCD�˿ڶ���---------------- 
#define	LCD_REST PBout(1) //LCD REST    		 PB1 	    
//LCD��ַ�ṹ��
typedef struct
{
	uint16_t LCD_REG;
	uint16_t LCD_RAM;
} LCD_TypeDef;
		    
#define LCD_BASE        ((u32)(0x60000000 | 0x0007FFFE))
#define LCD             ((LCD_TypeDef *) LCD_BASE)

#define WHITE         	 0xFFFF
#define BLACK         	 0x0000	  
#define BLUE         	 0x001F  
#define BRED             0XF81F
#define GRED 			 0XFFE0
#define GBLUE			 0X07FF
#define RED           	 0xF800
#define MAGENTA       	 0xF81F
#define GREEN         	 0x07E0
#define CYAN          	 0x7FFF
#define YELLOW        	 0xFFE0
#define BROWN 			 0XBC40
#define BRRED 			 0XFC07
#define GRAY  			 0X8430

#define DARKBLUE      	 0X01CF
#define LIGHTBLUE      	 0X7D7C
#define GRAYBLUE       	 0X5458
 
#define LIGHTGREEN     	 0X841F
//#define LIGHTGRAY        0XEF5B
#define LGRAY 			 0XC618

#define LGRAYBLUE        0XA651
#define LBBLUE           0X2B12

void spi_Init(void);													  
void LCD_Init(void);
void LCD_DisplayOn(void);
void LCD_DisplayOff(void);
void LCD_Clear(uint16_t Color);
void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);
void LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color);
void LCD_Fast_DrawPoint(uint16_t x,uint16_t y,uint16_t color);								//���ٻ���
void Draw_Circle(uint16_t x0,uint16_t y0,uint8_t r);										//��Բ
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);							//����
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);		   				//������
void LCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color);		   				//��䵥ɫ
void LCD_Color_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t *color);				//���ָ����ɫ
void LCD_ShowChar(uint16_t x,uint16_t y,uint8_t num,uint8_t size,uint8_t mode);						//��ʾһ���ַ�
// void LCD_ShowNum(uint16_t x,uint16_t y,u32 num,uint8_t len,uint8_t size);  						//��ʾһ������
// void LCD_ShowxNum(uint16_t x,uint16_t y,u32 num,uint8_t len,uint8_t size,uint8_t mode);				//��ʾ ����
void LCD_ShowString(uint16_t x,uint16_t y,uint16_t width,uint16_t height,uint8_t size,uint8_t *p);		//��ʾһ���ַ���,12/16����
	  
void showimage(uint16_t x,uint16_t y); //��ʾ40*40ͼƬ
void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue);
void LCD_WriteRAM_Prepare(void);
void LCD_WR_DATA8(uint8_t da);   //д8λ����  
 
void showhanzi16(unsigned int x,unsigned int y,unsigned char index);//16*16����
void showhanzi32(unsigned int x,unsigned int y,unsigned char index);//32*32����						  		 

#endif
